package com.mdd.admin.controller;

import com.mdd.admin.service.IProposalService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ProposalVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 建议反馈控制层
 * @author shenjian
 * @createTime 2023年03月04日 11:46:00
 */
@Slf4j
@RestController
@RequestMapping("api/proposal")
public class ProposalController {

    @Resource
    IProposalService iProposalService;

    /**
     * 建议列表
     * @param pageValidate
     * @return
     */
    @GetMapping("/list")
    public AjaxResult<?> list(@Validated PageValidate pageValidate) {
        PageResult<ProposalVo> pageResult = iProposalService.list(pageValidate);
        return AjaxResult.success(pageResult);
    }

    /**
     * 建议采纳
     * @param id
     * @param reply
     * @return
     */
    @GetMapping("/adopt")
    public AjaxResult<?> adopt(@Validated @IDMust @RequestParam("id") Integer id,
                               @RequestParam(value = "reply", required = false) String reply) {
        iProposalService.adopt(id, reply);
        return AjaxResult.success();
    }
}
